package com.yanggu.mapreduce.combiner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2019/12/9 0:00
 * @description:
 */
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

    private IntWritable value = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        //1. 累加求和
        int sum = 0;
        for (IntWritable intWritable : values) {
            sum += intWritable.get();
        }
        //2. 输出
        value.set(sum);
        context.write(key, value);
    }
}
